import React, {Component} from 'react';
import './Login.scss';
import axios from 'axios';
import {
    Button,
    Form,
    Input,
    Notification
} from 'element-react';

class Login extends Component {
    constructor(props) {
        super(props);

        this.state = {
            form: {
                password: '',
                name: ''
            }
        };
    }

    handleSubmit(e) {
        e.preventDefault();
        Notification({
            title: '提示',
            message: '登录成功',
            type: 'success'
        });
        this.props.history.push('/list');
        // return
        axios.post(`https://statest.kungeek.com/member/privates/member/qyxx/getAllIndustry`, this.state.form).then(res => {
            console.log(res)
         });
    }

    onChange(key, value) {
        this.setState({
            form: Object.assign({}, this.state.form, {[key]: value})
        });
    }

    render() {
        const list = (length) => {
            const res = [];
            for(let i = 0; i < length; i++) {
                res.push(<div className="trigger" key={i}></div>)
            }
            return res
        }
        return (
            <div className="loginPage">
                <p className="attention">接口中心</p>
                <div className="container">
                    {list(200)}
                    <div className="monitor">
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                        <div className="ball"></div>
                    </div>
                </div>
                <Form ref="form" model={this.state.form}  labelWidth="60" className="loginForm">
                    <Form.Item label="账户" prop="name">
                        <Input type="name" value={this.state.form.name} onChange={this.onChange.bind(this, 'name')}
                               autoComplete="off"/>
                    </Form.Item>
                    <Form.Item label="密码" prop="checkPass">
                        <Input type="password" value={this.state.form.password} onChange={this.onChange.bind(this, 'password')} autoComplete="off"/>
                    </Form.Item>
                    <Button type="primary" className="loginBtn" onClick={this.handleSubmit.bind(this)}>登录</Button>
                </Form>
            </div>
        )
    }
}

export default Login;
